package com.iims.market.domain.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.iims.market.domain.ContractType;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author fanpei
 */
@Data
public class CtraTreeSelect implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private Integer id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<CtraTreeSelect> children;

    public CtraTreeSelect() {

    }

    public CtraTreeSelect(ContractType contractType) {
        this.id = contractType.getCtraTypeId();
        this.label = contractType.getCtraTypeName();
        this.children = contractType.getChildren().stream().map(CtraTreeSelect::new).collect(Collectors.toList());
    }
}
